package com.oto.web.resource;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.oto.Constants;
import com.oto.model.FlowDO;

/**
 * @author xueqiang.mi
 * @since 2011-1-8
 */
@Path("/public")
@Component
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class PublicResource extends BaseResource {

	public List<FlowDO> getFlows() {
		return flowService.lattest();
	}

	@GET
	@Path("subscribe")
	@Produces("text/plain")
	public String subscribe(@QueryParam("flowId") long flowId) {
		if (getUserName() == null) {
			return Constants.STATUS_ERROR + " 您必须登录后才能订阅电话数据!";
		}
		if (accountService.sub(getUserName(), flowId)) {
			return Constants.STATUS_DONE;
		} else {
			return Constants.STATUS_ERROR + " 数据保存失败!";
		}
	}
}
